from multiprocessing import Queue
import multiprocessing
import redis


class AsyncCKProcess(multiprocessing.Process):
    def __init__(self, q: Queue, redis_addr: str, redis_port: int, ck_key: str):
        super().__init__()
        self.queue = q
        self.redis = redis.Redis(host=redis_addr, port=redis_port, db=0)
        self.ck_key = ck_key

    def run(self):
        while True:
            data = self.queue.get()
            if data is None:
                break
            self.redis.set(self.ck_key, data)
